<!--飘图--闭包-->
<html>
	<head>
		<meta charset="UTF-8">
		<title>飘图--闭包</title>
	</head>
	<body>
		<div id="box" style="position: absolute;left:0;top:0;z-index: 999;">
			<img src="../public/imgs/1.jpg" width="100" height="100"/>
		</div>
	</body>
	<script type="text/javascript">
		var box = document.getElementById("box");
		var pageH = document.documentElement.clientHeight;
		var pageX = document.documentElement.clientWidth;
		var x =1;//偏移量
		var y=1;
		var bleft=0;
		var btop=0;
	    bleft =box.style.left;
	    btop = box.style.top;
		function move(){
			if(parseInt(bleft)>=(pageX-100) || parseInt(bleft)<0){
				x=-x;//变向
			}
			if(parseInt(btop)>=(pageH-100) || parseInt(btop)<0){
				y=-y;
			}
			bleft = parseInt(bleft)+x+"px";
			btop  = parseInt(btop)+y+"px";
			box.style.left = bleft;
			box.style.top = btop;
		}
		var t= setInterval("move()",10);
		box.onmouseover= function (){
			clearInterval(t);
		}
		box.onmouseout=function(){
			t= setInterval("move()",10);
		}
	</script>
</html>